﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tank
{
    enum Direction
    {
        Left,
        right,
        down,
        Up
    }
    class Moveing : ClassObject
    {
        private Object _lock = new object();
        public Bitmap BitmapUp { get; set; }
        public Bitmap BitmapDown { get; set; }
        public Bitmap BitmapLeft { get; set; }
        public Bitmap BitmapRight { get; set; }
        public int Speet { get; set; }
        private Direction dir;
        public Direction Dir { get {
                return dir;
            }
            set {
                dir = value;
                Bitmap bmp = null;

                lock (_lock)
                {
                    switch (value)
                    {
                        case Direction.Up:
                            bmp = BitmapUp;
                            break;
                        case Direction.down:
                            bmp = BitmapDown;
                            break;
                        case Direction.Left:
                            bmp = BitmapLeft;
                            break;
                        case Direction.right:
                            bmp = BitmapRight;
                            break;
                        default:
                            bmp = BitmapUp;
                            break;
                    }
                    Width = bmp.Width;
                    Height = bmp.Height;
                }

            } }
        // 对自身的图片进行重写
        protected override Image GetImage()
        {
            Bitmap current = null;
            switch(Dir)
            {
                case Direction.Up:
                    current =  BitmapUp;
                    break;
                case Direction.down:
                    current = BitmapDown;
                    break;
                
                case Direction.Left:
                    current = BitmapLeft;
                    break;
                 
                case Direction.right:
                    current = BitmapRight;
                    break;
                default:
                    return BitmapUp;
            }
            current.MakeTransparent(Color.Black);
            return current;
        }
        public new void DrawSelf()
        {
            lock (_lock)
            {
                base.DrawSelf();
            }
        }
    }
}
